package com.xinchuang.controller.targetSystem;

import com.alibaba.fastjson.JSONObject;
import com.xinchuang.common.Result;
import com.xinchuang.service.targetSystem.IdeaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName AnalyzeController
 * @Description: TODO(写一段描述的话)
 * @Author zhangxuan
 * @Date 2022-09-06 10:54
 * @Verion V1.0
 */
@Api(value = "分析接口", tags = {"分析接口"})
@RestController
public class AnalyzeController {

    /**
     * 想定
     */
    private final String IDEA_PORT = "/ideaAnalyze";

    /**
     * 想定目标列表
     */
    private final String IDEA_TARGET_PORT = "/ideaTargetList";

    /**
     * 想定得分列表
     */
    private final String IDEA_VALUE_PORT = "/ideaValueList";

    /**
     * 清理想定
     */
    private final String CLEAT_IDEA = "/clearIdea";

    @Autowired
    private IdeaService ideaService;

    @ApiOperation(value = "新增想定阶段")
    @PostMapping(value = IDEA_PORT)
    public Result addIdeaStage(
            @RequestBody JSONObject json
    ) {
        String systemId = json.getString("systemId");
        List<String> targetList = json.getJSONArray("targetList").toJavaList(String.class);
        return ideaService.addIdeaStage(systemId, targetList);
    }

    @ApiOperation(value = "删除想定阶段")
    @DeleteMapping(value = IDEA_PORT)
    public Result delIdeaStage(
            @RequestParam(value = "systemId") String systemId,
            @RequestParam(value = "stage") Integer stage
    ) {
        return ideaService.deleteIdeaStage(systemId, stage);
    }

    @ApiOperation(value = "清理想定阶段")
    @DeleteMapping(value = CLEAT_IDEA)
    public Result clearIdea(
            @RequestParam(value = "systemId") String systemId
    ) {
        return ideaService.cleatIdea(systemId);
    }

    @ApiOperation(value = "查询想定阶段")
    @GetMapping(value = IDEA_PORT)
    public Result selectIdeaStageList(
            @RequestParam(value = "systemId") String systemId
    ) {
        return ideaService.selectIdeaList(systemId);
    }

    @ApiOperation(value = "查询想定目标列表")
    @GetMapping(value = IDEA_TARGET_PORT)
    public Result selectIdeaTargetList(
            @RequestParam(value = "systemId") String systemId,
            @RequestParam(value = "system", defaultValue = "true") Boolean system,
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        return ideaService.selectIdeaTargetList(systemId, system, pageNum, pageSize);
    }

    @ApiOperation(value = "查询想定得分列表")
    @GetMapping(value = IDEA_VALUE_PORT)
    public Result selectIdeaValueList(
            @RequestParam(value = "systemId") String systemId
    ) {
        return ideaService.selectIdeaValueList(systemId);
    }

}